<script>
	import {
		getuser_location,
		get_integral_discount,
		getAllLable
	} from 'api/api.js'
	export default {
		globalData: {
			avatarUrl: "http://xiaowen.cool:86/bst/avatar.png",
		},

		onLaunch: function() {
			this.dataInit()
			this.getAllLable()
			let that = this
			/**
			 * 检测当前的小程序
			 * 是否是最新版本，是否需要下载、更新
			 */
			console.log('检查新版本更新!99999999999999999')
			that.autoUpdate()
			setInterval(() => {
				that.getlocation()
			}, 100000)
		},

		methods: {
			// 初始化
			dataInit() {
				get_integral_discount().then(res => {
					uni.setStorageSync('discount', res.msg)
				})
			},
			// 获取所有标签
			getAllLable() {
				getAllLable().then(res => {
					uni.setStorageSync('tag', res.data)
				})

			},
			autoUpdate: function() {

				var self = this
				// 获取小程序更新机制兼容
				if (wx.canIUse('getUpdateManager')) {
					const updateManager = wx.getUpdateManager()
					//1. 检查小程序是否有新版本发布

					updateManager.onCheckForUpdate(function(res) {
						// 请求完新版本信息的回调
						console.log('测试啊啊啊', res)
						if (res.hasUpdate) {
							console.log('检查新版本更新!', res.hasUpdate)
							//检测到新版本，需要更新，给出提示
							wx.showModal({
								title: '更新提示',
								content: '检测到新版本，是否下载新版本并重启小程序？',
								success: function(res) {
									if (res.confirm) {
										//2. 用户确定下载更新小程序，小程序下载及更新静默进行
										self.downLoadAndUpdate(updateManager)
									} else if (res.cancel) {
										//用户点击取消按钮的处理，如果需要强制更新，则给出二次弹窗，如果不需要，则这里的代码都可以删掉了
										wx.showModal({
											title: '温馨提示~',
											content: '本次版本更新涉及到新的功能添加，旧版本无法正常访问的哦~',
											showCancel: false, //隐藏取消按钮
											confirmText: "确定更新", //只保留确定更新按钮
											success: function(res) {
												if (res.confirm) {
													//下载新版本，并重新应用
													self.downLoadAndUpdate(
														updateManager)
												}
											}
										})
									}
								}
							})
						}
					})
				} else {
					// 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
					wx.showModal({
						title: '提示',
						content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
					})
				}
			},
			/**
			 * 下载小程序新版本并重启应用
			 */
			downLoadAndUpdate: function(updateManager) {
				var self = this
				wx.showLoading();
				//静默下载更新小程序新版本
				updateManager.onUpdateReady(function() {
					wx.hideLoading()
					//新的版本已经下载好，调用 applyUpdate 应用新版本并重启
					updateManager.applyUpdate()
				})
				updateManager.onUpdateFailed(function() {
					// 新的版本下载失败
					wx.showModal({
						title: '已经有新版本了哟~',
						content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~',
					})
				})
			},
			// }),
			getlocation() {
				uni.getLocation({
					type: 'wgs84',
					success(res) {
						console.log('用户位置信息', res)
						// const latitude = res.latitude   //纬度
						// const longitude = res.longitude  //经度
						let data = {
							longitude: res.longitude,
							latitude: res.latitude
						}
						console.log('登录信息', uni.getStorageSync('islogin'))
						if (!uni.getStorageSync('islogin')) return
						getuser_location(data).then(res => {

						})
					}
				})
			}
		},
		onHide: function() {
			console.log('App Hide');
		},
		beforeCreate() {
			uni.setStorageSync('uploadUrl', 'https://bst.schainbaas.com/api/upload/image')
			uni.getSystemInfo({
				success: function(data) {
					// 将其赋值给this
					let value = data.statusBarHeight + 'px'
					uni.setStorageSync('statusBarHeight', value)
					console.log('导航栏高度', value)
				},
			})
		},

	};

	//  访问密钥 key youjiaxcx20210620
</script>

<style lang="scss">
	/*每个页面公共css */
	.home_top {
		/* padding-left: -25px; */
		background-image: url('http://xiaowen.cool:86/yjky/yjkybg.png');
		background-size: cover;
		width: 750upx;
		height: 370upx;
		padding: 20upx;
		box-sizing: border-box;
		/* background-color: #4cd964; */
		flex-direction: row;
		align-items: center;
	}

	.bgf {
		background-color: #FFFFFF;
	}

	.home_top1 {
		/* padding-left: -25px; */
		background-image: url('http://xiaowen.cool:86/yjky/yjkybg.png');
		background-repeat: no-repeat;
		background-position: 0 -215rpx;
		background-size: cover;
		// border-radius: 0 0 50rpx 50rpx;
		width: 750upx;
		height: 200upx;
		padding: 20upx;
		box-sizing: border-box;
		/* background-color: #4cd964; */
		flex-direction: row;
		align-items: center;
	}

	@font-face {
		font-family: 'iconfont';
		/* Project id 2654934 */
		src: url('//at.alicdn.com/t/font_2654934_wixdg85resk.woff2?t=1632295665258') format('woff2'),
			url('//at.alicdn.com/t/font_2654934_wixdg85resk.woff?t=1632295665258') format('woff'),
			url('//at.alicdn.com/t/font_2654934_wixdg85resk.ttf?t=1632295665258') format('truetype');
	}

	.iconfont {
		font-family: iconfont;
		// width: 40upx;
		// height: 90upx;
		// line-height: 90upx;
		font-size: 42upx;
		// color: #999999;
		text-align: center;
		/* font-family: texticons; */
		margin-right: 20upx;
	}


	body,
	html {
		// background-color:rgba(0,0,0,.1);
		// background-color: #fafafa;
		font-size: 28rpx;
	}

	.bg1 {
		background-color: #D8E6FF;
	}

	.block {
		display: block;
	}

	.warp {
		width: 100%;
		height: 100%;
		background-color: #fafafa;
	}

	.line {
		width: 100%;
		background-color: rgba(0, 0, 0, .1);
		height: 1rpx;
		margin-bottom: 20rpx;
	}

	.c66 {
		color: #666666;
	}

	.mt10 {
		margin-top: 10rpx;
	}

	.mt20 {
		margin-top: 20rpx;
	}

	.mt30 {
		margin-top: 30rpx;
	}

	.ml10 {
		margin-left: 10rpx;
	}

	.ml20 {
		margin-left: 20rpx;
	}

	.ml30 {
		margin-left: 30rpx;
	}

	.mr10 {
		margin-right: 10rpx;
	}

	.mr20 {
		margin-right: 20rpx;
	}

	.mr30 {
		margin-right: 30rpx;
	}

	.flex {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bg-color {
		background-color: #029E8E;
	}



	.touxiang {
		width: 60rpx;
		height: 60rpx;
		border-radius: 10rpx;
	}

	.suolue {
		width: 150rpx;
		height: 150rpx;
		border-radius: 10rpx;
	}

	.icon {
		width: 45upx;
		height: 45upx;
		margin-top: 26upx;
	}

	.s-title {
		font-size: 35rpx;
		font-weight: 600;
	}

	.s-title2 {
		font-size: 26rpx;
		color: #999999;
	}

	.empty_box {
		height: 200rpx;
		width: 100%;
	}


	/* 以下样式用于 hello uni-app 演示所需 */
	page {
		// background-color: #F4F5F6;
		height: 100%;
		font-size: 28upx;
		line-height: 1.8;
	}

	.warp {
		background-color: #F4F5F6;
		height: 100%;
		font-size: 28upx;
		line-height: 1.8;
	}

	.uni-header-logo {
		padding: 30upx;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 10upx;
	}

	.uni-header-image {
		width: 100px;
		height: 100px;
	}

	.uni-hello-text {
		color: #7A7E83;
	}

	.uni-hello-addfile {
		text-align: center;
		line-height: 300upx;
		background: #FFF;
		padding: 50upx;
		margin-top: 10px;
		font-size: 38upx;
		color: #808080;
	}

	button {
		padding: 0upx;
		margin: 0upx;
		border: none;
		border-radius: 0upx;
		box-sizing: border-box;
	}

	button {
		width: 450upx;
		height: 80upx;
		margin: 94upx auto 0;
		background: #029E8E;
		border-radius: 40upx;
		line-height: 80rpx !important;
		// box-shadow: 0upx 5upx 10upx #5490FE;
		color: #fff;
	}

	.sharebtn1 {
		margin: 94upx auto 0;
		color: #fff;
	}

	.button-hover {
		transform: translate(3upx, 3upx) !important;
		transition: .2s;
	}

	button::after {
		border: none
	}

	.round {
		border-radius: 50%;
	}

	.cmain {
		color: #029E8E;
	}

	.bmain {
		background-color: #029E8E;
	}

	.box-s {
		box-shadow: 0rpx 0rpx 10rpx 10rpx rgba(0, 0, 0, .1);
	}

	.box-s1 {
		box-shadow: 0rpx 0rpx 10rpx 10rpx rgba(0, 0, 255, .05);
	}

	.box-s3 {
		box-shadow: 0rpx 0rpx 10rpx 10rpx rgba(0, 0, 0, .03);
	}

	.home_top {
		/* padding-left: -25px; */
		background-image: url('http://xiaowen.cool:86/yjky/yjkybg.png');
		background-size: cover;
		width: 750upx;
		height: 370upx;
		padding: 20upx;
		box-sizing: border-box;
		/* background-color: #4cd964; */
		flex-direction: row;
		align-items: center;
	}

	.nav-icon {
		//自定义导航栏图标
		font-size: 50rpx;
		width: 30%;
		line-height: 50rpx;
		width: 50%;
		text-align: left;
	}

	.w50 {
		width: 50%;
		margin-left: -166rpx;
	}

	.pd30 {
		padding: 0 30rpx;
	}

	.fs20 {
		font-size: 20rpx;
	}

	.word-big {
		color: #333333;
		font-size: 40rpx;
	}

	.word-small {
		color: #999999;
		font-size: 28rpx;
	}

	.cff {
		color: #FFFFFF;
	}

	.bff {
		background-color: #FFFFFF;
	}

	// 单行超出隐藏 注意给width

	.word-omit {
		/*word-break:break-all;*/
		white-space: nowrap;
		/*强制在一行显示*/
		text-overflow: ellipsis;
		/*设置超出内容显示...*/
		overflow: hidden;
		/*一定不能少 超出的内容进行隐藏*/
	}

	// 文本隐藏
	.text-omit {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		color: #999999;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;

	}

	.red {
		color: #FD3833;
	}

	// 空页面
	.empty {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		flex-wrap: wrap;

		.empty-s {
			font-size: 150rpx;
			color: #999999;
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.money {
		color: #FD3833;
		font-size: 36rpx;
	}

	.s-money {
		color: #FD3833;
		font-size: 24rpx;
	}


	input:focus {
		border-color: #66afe9 !important;
		outline: 0;
		-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
		box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6)
	}
	/deep/.htz-image-upload-Item-add {
	    font-size: 105rpx;
	    text-align: center;
	    border: 1px dashed #d9d9d9;
	    color: #d9d9d9;
	    line-height: 160rpx;
	}
	
	.select {
		position: fixed;
		width: 100%;
		line-height: 150rpx;
		height: 150rpx;
		background-color: #FFFFFF !important;
		z-index: 99;
		top: 0rpx;
	}
	.searchGood {
		margin-top: 30rpx;
		display: flex;
		justify-content: flex-start;
		padding: 0 30rpx;
		width: 100%;
		height: 60rpx;
	}
	
	.searchGood .search {
		background-color: #F8F8F8;
		border-radius: 30rpx;
		padding-left: 0rpx;
		width: 65%;
	}
	
	.searchGood .search .input {
		width: 100%;
		border-radius: 33rpx;
		padding: 0 35rpx;
		box-sizing: border-box;
		height: 66rpx;
	}
	
	.searchGood .search .input input {
		font-size: 28rpx;
	}
	
	.searchGood .search .input .placeholder {
		color: #999999 !important;
	}
	
	.searchGood .search .input .iconfont {
		color: #999999;
		font-size: 35rpx;
	}
	
	.searchGood .search .bnt {
		width: 120rpx;
		text-align: right;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 30rpx;
		color: #999999;
	}
	
	.searchGood .title {
		font-size: 28rpx;
		color: #999999;
		margin: 50rpx 30rpx 25rpx 30rpx;
	}
	
	.searchGood .list {
		padding-left: 10rpx;
	}
	
	.searchGood .list .item {
		font-size: 26rpx;
		color: #454545;
		padding: 0 21rpx;
		height: 60rpx;
		border-radius: 3rpx;
		line-height: 60rpx;
		border: 1rpx solid #aaa;
		margin: 0 0 20rpx 20rpx;
	}
	
	.searchGood .line {
		border-bottom: 1rpx solid #eee;
		margin: 20rpx 30rpx 0 30rpx;
	}
	
	// 主题色 #029E8E
</style>
